<!--
*******************************************************************************
 * Copyright © 2021-2022 VMware, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 *
 * @author: Huaqiao Zhang, <huaqiaoz@vmware.com>
 *******************************************************************************
 -->

 <div class="card">
     <div class="card-header">
        <i class="fa fa-list text-danger"></i> Subscription List
     </div>
     <div class="card-body p-0 position-relative">
        <div class="bg-light px-2 py-2">
            <div class="btn-group btn-group-sm" role="group">
                <button class="btn btn-primary" (click)="refresh()">
                    <span><i class="fa fa-refresh mr-1"></i>Refresh</span> 
                </button>
                <button type="button" class="btn btn-info"  routerLink="../add-subscription">
                    <span><i class="fa fa-plus mr-1"></i>Add</span>
                </button>
                <button type="button" class="btn btn-success" (click)="edit()" [disabled]="subscriptionSelected.length !== 1">
                    <span><i class="fa fa-edit mr-1"></i>Edit</span>
                </button>
                <button type="button" class="btn btn-danger" (click)="deleteConfirm()" [disabled]="subscriptionSelected.length === 0">
                    <span><i class="fa fa-trash mr-1"></i>Delete</span>
                </button>
              </div>
        </div>
        <div class="table-responsive ">
            <table class="table table-hover text-truncate ">
                <thead class="thead-light">
                    <tr>
                      <th scope="col"><input type="checkbox" role="button" [checked]="isCheckedAll" (click)="selectAll($event)"></th>
                      <th scope="col">ID</th>
                      <th scope="col">Name</th>
                      <th scope="col">Description</th>
                      <th scope="col">Categories</th>
                      <th scope="col">Labels</th>
                      <th scope="col">Channels</th>
                      <th scope="col">Receiver</th>
                      <th scope="col">ResendLimit</th>
                      <th scope="col">ResendInterval</th>
                      <!-- <th scope="col">Created</th>
                      <th scope="col">Modified</th> -->
                    </tr>
                </thead>
                <tbody>
                    <tr *ngFor="let sub of subscriptionList" [class.table-active]="isChecked(sub.name)">
                        <td> <input type="checkbox" role="button"  [checked]="isChecked(sub.name)" (click)="selectOne($event,sub)"></td>
                        <td class="user-select-all">{{sub.id}}</td>
                        <td class="user-select-all">{{sub.name}}</td>
                        <td>{{sub.description}}</td>
                        <td>{{sub.categories}}</td>
                        <td>{{sub.labels}}</td>
                        <td class="text-center">
                            <span class="badge badge-primary text-light" role="button" (click)="checkChannels(sub)"> 
                                <i class="fa fa-paper-plane-o"></i> {{sub.channels.length}}
                            </span>
                        </td>
                        <td>{{sub.receiver}}</td>
                        <td>{{sub.resendLimit}}</td>
                        <td>{{sub.resendInterval}}</td>
                        <!-- <td>{{sub.created | date:'yyyy-MM-dd hh:mm:ss'}}</td>
                        <td>{{sub.modified | date:'yyyy-MM-dd hh:mm:ss' }}</td> -->
                    </tr>
                </tbody>
            </table>
        </div>
     </div>
     <div class="card-footer text-muted p-1">
        <nav aria-label="navigation">
            <ul class="pagination justify-content-end m-0">
                <li class="page-item mr-2 mt-1">
                    <span class="align-middle">items per page</span>
                </li>
                <li class="page-item mr-2 ">
                    <select class="form-control" name="pageLimit" id="pageLimit" [(ngModel)]="pageLimit" (ngModelChange)="onPageSelected()">
                        <option value="5">5</option>
                        <option value="10">10</option>
                        <option value="20">20</option>
                    </select>
                </li>
                <li class="page-item mr-1">
                    <button class="page-link btn" (click)="prePage()" [disabled]="pagination === 1"> <i class="fa fa-angle-double-left"></i> Previous</button>
                </li>
                <li class="page-item" >
                    <button class="page-link btn" (click)="nextPage()" [disabled]="this.pageLimit > subscriptionList.length">Next <i class="fa fa-angle-double-right"></i></button>
                </li>
            </ul>
        </nav>
    </div>
 </div>

 <!-- <div class="card">
     <div class="card-header">
        <i class="fa fa-paper-plane-o text-danger mr-2"></i>
         <span>{{checkedSubscription.name}} Associated Channels List</span>
     </div>
     <div class="card-body">

    </div>
 </div> -->

 <div class="modal fade" id="deleteConfirmDialog" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="deleteConfirmDialogLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title text-danger" id="deleteConfirmDialogLabel">
                    <i class="fa fa-warning"></i>
                    Warning
                </h5>  
            </div>
            <div class="modal-body">
                The data will be permanently erased!!! Are you sure to execute delete operation？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-danger" (click)="deleteSubs()">Confirm</button>
            </div>
        </div>
    </div>
</div>